export function isString (o) { //是否字符串
  return Object.prototype.toString.call(o).slice(8, -1) === 'String'
}

export function isNumber (o) { //是否数字
  return Object.prototype.toString.call(o).slice(8, -1) === 'Number'
}

export function isObj (o) { //是否对象
  return Object.prototype.toString.call(o).slice(8, -1) === 'Object'
}

export function isArray (o) { //是否数组
  return Object.prototype.toString.call(o).slice(8, -1) === 'Array'
}

export function isDate (o) { //是否时间
  return Object.prototype.toString.call(o).slice(8, -1) === 'Date'
}

export function isBoolean (o) { //是否boolean
  return Object.prototype.toString.call(o).slice(8, -1) === 'Boolean'
}

export function isFunction (o) { //是否函数
  return Object.prototype.toString.call(o).slice(8, -1) === 'Function'
}

export function isNull (o) { //是否为null
  return Object.prototype.toString.call(o).slice(8, -1) === 'Null'
}

export function isUndefined (o) { //是否undefined
  return Object.prototype.toString.call(o).slice(8, -1) === 'Undefined'
}

export function isFalse (o) {
  if (o == '' || o == undefined || o == null || o == 'null' || o == 'undefined' || o == 0 || o == false || o == NaN) return true
  return false
}

export function isTrue (o) {
  return !this.isFalse(o)
}

// 是否是数字或字符串型的数字
export const isFieldNumber = value => {
  value = parseFloat(value)
  return isNaN(value) ? false : true
}

export const isJSON = str => {
  if (typeof str == 'string') {
    try {
      var obj=JSON.parse(str)
      if(typeof obj == 'object' && obj ){
        return true
      }else{
        return false
      }

    } catch(e) {
      // console.log('error：'+str+'!!!'+e);
      return false
    }
  }
  // console.log('It is not a string!')
}

export default {
  isString, isNumber, isObj, isDate, isBoolean, isFunction, isNull, isUndefined, isFalse, isTrue
}